<%@ page language="java"
	import="java.util.*,org.jbpm.api.*,org.jbpm.api.task.*"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title>请假工作流系统 --- JBPM 4.4</title>
	</head>

	<body>
		<center>
			<h2>
				<%
					String username = session.getAttribute("username").toString();
				 %>
				欢迎登录：<%=username%> 
				<%
					if(Integer.valueOf(session.getAttribute("rule").toString())==1){
						out.print("老师");
					}else{
						out.print("同学");
					}	
				%>
			</h2>
			<br>
			<%
				List<ProcessDefinition> pdList = (List<ProcessDefinition>) session
						.getAttribute("pdList");
				List<ProcessInstance> piList = (List<ProcessInstance>) session
						.getAttribute("piList");
				List<Task> taskList = (List<Task>) session.getAttribute("taskList");
			%>
			<table border="1" width="100%">
				<caption>
					流程定义
				</caption>
				<thead>
					<tr>
						<td>
							id
						</td>
						<td>
							name
						</td>
						<td>
							version
						</td>
						<td>
							operation
						</td>
					</tr>
				</thead>
				<tbody>
					<%
						for (ProcessDefinition pd : pdList) {
					%>
					<tr>
						<td><%=pd.getId()%></td>
						<td><%=pd.getName()%></td>
						<td><%=pd.getVersion()%></td>
						<td>
							<a href="leave?action=start&id=<%=pd.getId()%>">启动流程</a>
						</td>
					</tr>
					<%
						}
					%>
				</tbody>
			</table>
			<br>
			<table border="1" width="100%">
				<caption>
					流程实例
				</caption>
				<thead>
					<tr>
						<td>
							id
						</td>
						<td>
							activity
						</td>
						<td>
							state
						</td>
						<td>
							operation
						</td>
					</tr>
				</thead>
				<tbody>
					<%
						for (ProcessInstance pi : piList) {
					%>
					<tr>
						<td><%=pi.getId()%></td>
						<td><%=pi.findActiveActivityNames()%></td>
						<td><%=pi.getState()%></td>
						<td>
							<a href="leave?action=view&id=<%=pi.getId()%>">查看</a>
						</td>
					</tr>
					<%
						}
					%>
				</tbody>
			</table>
			<br>
			<table border="1" width="100%">
				<caption>
					待办任务
				</caption>
				<thead>
					<tr>
						<td>
							id
						</td>
						<td>
							name
						</td>
						<td>
							&nbsp;
						</td>
					</tr>
				</thead>
				<tbody>
					<%
						for (Task task : taskList) {
					%>
					<tr>
						<td><%=task.getId()%></td>
						<td><%=task.getName()%></td>
						<td>
							<a href="<%=task.getFormResourceName()%>?id=<%=task.getId()%>">查看</a>
						</td>
					</tr>
					<%
						}
					%>
				</tbody>
			</table>
		</center>
	</body>
</html>
